import com.bunde.repo.InventoryExcelManager;
import com.bunde.repo.com.bunde.service.InventoryService;
import com.bunde.repo.model.InventoryModel;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Timer;

public class MyTest {
    @Test
    public void loadExcelDataTest(){
        String filename = "F:\\tmp\\learn_repo\\excel_demo\\excel_read_test.xlsx";



        InventoryExcelManager inventoryExcelManager = new InventoryExcelManager();
        try {
            Map<String, List<List<Object>>> res = inventoryExcelManager.loadExcel(filename);
            for (Map.Entry<String, List<List<Object>>> entry : res.entrySet()){
                System.out.println("表名：" + entry.getKey());
                List<List<Object>> data = entry.getValue();
                for(int i = 0; i < data.size(); i++){
                    if (i == 0) {
                        System.out.println("header: ");
                    }

                    List<Object> rowData = data.get(i);
                    if(rowData.size() == 0){
                        System.out.println("预留行为空");
                    }else {
                        for (int j = 0; j < rowData.size(); j++) {
                            System.out.print(rowData.get(j) + " ");
                        }
                        System.out.println();
                    }

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 文件写入测试
    @Test
    public void writeTest(){
        InventoryExcelManager inventoryExcelManager = new InventoryExcelManager();
        InventoryService inventoryService = new InventoryService();
        int startWeek = 2022, endWeek = 2028;
        try {
            inventoryExcelManager.writeToExcel(inventoryService.getInventoryData(startWeek, endWeek), "excel_write_text.xlsx", startWeek, endWeek);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
